<%@ page import="org.subject.entity.User" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%--引入 jstl--%>
<%@include file="common/tag.jsp" %>
<!DOCTYPE html>
<%-- 获取资源根路径--%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<html>
<script src="http://cdn.static.runoob.com/libs/jquery/2.1.1/jquery.min.js"></script>
<head>
    <title>首页</title>
    <%@include file="common/head.jsp" %>
    <script src="/./resource/js/list.js"></script>
    <style>
        a {
            text-decoration: none
        }

        .pageNum {
            margin: 0px auto;
        }

        .bordercolor {
            border-style: solid;
            border-color: #CBEAFA;
        }

        .bordercolor td {
            height: 20px;
        }

        html, body {
            margin: 0;
            padding: 0;
            height: 100%;
        }

        #container {
            min-height: 100%;
            height: auto !important;
            height: 100%; /*IE6不识别min-height*/
            position: relative;
        }

        #page {
            width: 100%;
            margin-bottom: 50px; /*等于footer的高度*/
        }
    </style>

    <script>
        function save() {
            /*   var msg=$("#submitForm").serialize();
             alert(msg);
             //遍历 table表格
             var s3 = document.getElementsByTagName("table")[0]; //获取第一个表格
             for(var i=0;i<s3.rows.length;i++){
             for(var j=0;j<s3.rows[i].cells.length;j++){
             alert(s3.rows[i].cells[j].innerHTML);
             }
             }*/

            var $seat = $(".seat");
            var $grade = $(".grade");
            /*var num_grade_obj = {};
             num_grade_obj.seat = [];
             num_grade_obj.grade = [];*/

            var $registrationId = $(".registrationId");
//            var seat_grade_obj=[];
            var arr = new Array();

            for (var i = 0; i < $seat.length; i++) {
                /*num_grade_obj.seat[i] = {};
                 num_grade_obj.seat[i]["seat"] = $seat.eq(i).val();
                 num_grade_obj.grade[i] = {};
                 num_grade_obj.grade[i]["grade"] = $grade.eq(i).val();*/

//                seat_grade_obj.register={seat:$seat.eq(i).val(),registrationId:$registrationId.eq(i).val(),grade:$grade.eq(i).val()};
//                seat_grade_obj[i]=seat_grade_obj.register;
                arr.push({
                    registrationId: $registrationId.eq(i).val(),
                    seat: $seat.eq(i).val(),
                    grade: $grade.eq(i).val()
                });
//                arr.push({registrationId:"hell",seat:"hell",grade:"hell"});
            }
            console.log(arr);
            $.ajax({
                type: "post",
                contentType: "application/json",
                url: "<%=request.getContextPath()%>/regist/set",
                data: JSON.stringify(arr),
//                data: {name:"zhangkai",age:18},
                dataType: "json",
                success: function (data) {
//                    console.log(num_grade_obj);
                },
                error: function (e) {
                }
            });
        }

    </script>
</head>
<body background="/./resource/images/bg.jpg" style="background-size: cover;background-repeat: no-repeat;">
<%--页面显示部分--%>
<div id="container" class="container">
    <jsp:include page="common/Top.jsp"/>
    <div id="page" class="panel panel-default">
        <div class="panel-heading">
            <h5>${message.messageTitle}报名列表</h5>
        </div>
        <div class="panel-body">
            <c:choose>
                <c:when test="${sessionScope.user != null}">
                    <div class="col-md-12">
                        <form id="submitForm" <%--action="/regist/setcord" method="post"--%>>
                            <table border="1" width="100%" class="bordercolor" style="margin-top: 20px">
                                <thead>
                                <tr bgcolor="#CBEAFA">
                                    <th text-align="center">序号</th>
                                    <th align="center">学号</th>
                                    <th align="center">姓名</th>
                                    <th align="center">座位号</th>
                                    <th align="center">成绩</th>
                                    <th align="center">文件</th>
                                    <th align="center" hidden>id</th>
                                </tr>
                                </thead>
                                <tbody>
                                <c:forEach items="${registeMessages}" var="registMessage" varStatus="status">
                                    <tr <c:if test="${status.index % 2 != 0}">style='background-color:#ECF6EE;'</c:if>>
                                        <td style="height:40px" align="center">${status.index + 1}</td>
                                        <td align="center">${registMessage.userNumber}</td>
                                        <td align="center">${registMessage.userName}</td>
                                        <td align="center"><input class="seat" type="text"
                                                                  style="border: 1px grey;height: 30px;width: 60px"
                                                                  value="${registMessage.registrationSeat}">
                                        </td>
                                        <td align="center"><input class="grade" type="text"
                                                                  style="border: 1px grey;height: 30px;width: 60px"
                                                                  value="${registMessage.registrationScore}">
                                        </td>
                                        <td align="center">
                                            <c:choose>
                                                <c:when test="${registMessage.registrationRemark!=null}">
                                                    ${registMessage.registrationRemark} <a
                                                        href='${pageContext.request.contextPath }/regist/dowload?address=${registMessage.registrationRemark}'>下载</a>
                                                </c:when>
                                                <c:otherwise>

                                                </c:otherwise>
                                            </c:choose>
                                        </td>
                                        <td hidden>
                                            <input class="registrationId" type="text"
                                                   value="${registMessage.registrationId}">
                                        </td>
                                            <%--<td align="center">${user.userName}</td>--%>
                                            <%--<td><fmt:formatDate value="${message.createTime}" pattern="yyyy-MM-dd"/></td>
                                            <td>
                                                <a href="/message/detail?messageId=${message.messageId}">查看</a>&nbsp;&nbsp;&nbsp;
                                                <a href="/message/delete?messageId=${message.messageId}">删除</a>
                                            </td>--%>
                                    </tr>
                                </c:forEach>
                                </tbody>
                            </table>
                            <input class="btn" type="button"
                                   style="margin-left: 10px;margin-top: 20px"
                                   value="保存" onclick="save()"/>
                        </form>

                        <script>
                            Document.write($("#submitForm").serialize());
                        </script>
                    </div>
                </c:when>
            </c:choose>
        </div>
    </div>
    <jsp:include page="common/footer.jsp"/>
</div>
</body>
<!-- jQuery文件。务必在bootstrap.min.js 之前引入 -->

<!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
<script src="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</html>